<template>
  <!-- 外层滚动容器 -->
  <div class="h-screen overflow-y-auto bg-gray-50">

      <!-- 顶部导航栏 -->
      <header class="bg-primary text-white p-3 flex items-center justify-between">
        <div class="flex items-center">
          <i class="i-heroicons-marker text-xl mr-1"></i>
          <span class="text-lg font-medium">沈阳市规划大厦</span>
          <i class="i-heroicons-chevron-down text-base ml-1"></i>
        </div>
      </header>

      <!-- 搜索框 -->
    <div class="sticky top-0 z-10">
      <div class="bg-primary p-3">
        <div class="bg-white flex items-center px-4 py-2 ">

          <input
            type="text"
            placeholder="搜索饿了么商家、商品名称"
            class="w-full text-gray-600 border-0 text-center placeholder:text-center"
          />
          <i class="i-mdi-magnify text-gray-400 text-lg mr-2"></i>
        </div>
      </div>
    </div>

    <main class="pb-20">
      <!-- 分类列表 -->
      <ul class="grid grid-cols-5 gap-2 p-4">
        <li
          v-for="(item, index) in categories"
          :key="index"
          class="flex flex-col items-center cursor-pointer"
        >
          <img :src="item.icon" class="w-16 h-16 sm:w-20 sm:h-20 mb-1 object-contain" />
          <p class="text-xs sm:text-sm text-gray-700">{{ item.name }}</p>
        </li>
      </ul>
      
      <!-- 套餐推荐 -->
      <div class="relative mx-4">
        <!-- 背景图片 -->
        <img 
          src="@/assets/images/index_banner.png" 
          alt="品质套餐" 
          class="w-full h-50 sm:h-56 md:h-64 object-cover rounded-lg"
        >
        
        <!-- 文字 -->
        <div class="absolute inset-0 flex flex-col justify-between p-4 sm:p-6 text-white">
          <!-- 上部文字 -->
          <div>
            <h3 class="text-black text-2xl sm:text-3xl md:text-4xl font-bold mb-1">品质套餐</h3>
            <p class="text-gray-500 text-xl sm:text-2xl md:text-3xl opacity-90">搭配齐全吃得好</p>
          </div>
          
          <!-- 底部按钮 -->
          <div class="flex text-orange text-xl sm:text-2xl items-center justify-start gap-1 font-medium">
            <span>立即抢购</span>
            <div class="i-mdi-chevron-right text-lg"></div>
          </div>
        </div>
      </div>

      <!-- 会员开通 -->
      <div class="bg-#feedc1 h-12 sm:h-14 p-4 flex justify-between items-center mx-4 mt-4 rounded-lg">
        <!-- 左侧 -->
        <div class="flex items-center gap-2">
          <img src="@/assets/images/super_member.png" class="w-8 h-8 sm:w-10 sm:h-10">
          <span class="font-bold text-xl sm:text-2xl md:text-3xl text-#644F1B">超级会员</span>
          <span class="text-black">·</span>
          <span class="font-light text-sm sm:text-base md:text-xl">每月享超值权益</span>
        </div>
        <!-- 右侧：开通按钮 -->
        <div class="flex items-center gap-1 text-black cursor-pointer">
          <span class="font-light text-sm sm:text-base md:text-xl">立即开通</span>
          <div class="i-mdi-chevron-right" />
        </div>
      </div>
      
      <!-- 商家推荐 -->
      <div class="h-16 sm:h-20 flex justify-center items-center text-#888 gap-3 sm:gap-5 p-4 mt-1">
        <h3 class="text-2xl sm:text-3xl md:text-4xl font-normal">------</h3>
        <h3 class="text-2xl sm:text-3xl md:text-4xl font-normal">推荐商家</h3>
        <h3 class="text-2xl sm:text-3xl md:text-4xl font-normal">------</h3>
      </div>
      
      <!-- 推荐条件 -->
      <div class="flex justify-between items-center text-sm sm:text-base md:text-xl gap-2 sm:gap-2 p-4">
        <span class="text-gray-800">综合排序</span>
        <span class="text-gray-800">距离最近</span>
        <span class="text-gray-800">销量最高</span>
        <span class="text-gray-800">筛选</span>
      </div>

      <!-- 商家列表 -->
      <div class="bg-white">
        <div 
          v-for="(shop, index) in businessinfoes" 
          :key="index" 
          class="border-b border-gray-100 last:border-b-0 d-border"
        >
          <div class="flex p-4 ">
            <!-- 左侧店铺图片 -->
            <div class="w-16 h-16 sm:w-20 sm:h-20 mr-3 mt-4 flex-shrink-0">
              <img 
                :src="shop.icon" 
                class="w-full h-full object-cover"
              />
            </div>
            
            <!-- 右侧店铺信息 -->
            <div class="flex-1 min-w-0">
              <!-- 第一部分：基本信息 -->
              <div class="mb-2">
                <!-- 店铺名称和评分 -->
                <div class="flex justify-between items-start mb-1">
                  <!-- 添加点击 -->
                  <h3 @click="goToBusinessInfo(shop.id)" class="text-base sm:text-lg font-semibold text-gray-800 truncate cursor-pointer">{{ shop.name }}</h3>
                  <div class="flex flex-col items-center text-xs text-gray-500">
                    <span class="text-blue-500 mr-2 mt-4">{{ shop.deliveryType || '蜂鸟专送' }}</span>
                    <span>{{ shop.distance || '3.22km' }} | {{ shop.deliveryTime || '30分钟' }}</span>
                  </div>
                </div>
                
                <!-- 价格和销量 -->
                <div class="flex text-xs text-gray-500 mb-1">
                  <span class="text-yellow-400 mr-1">★★★★★</span>
                  <span class="font-bold mr-1">{{ shop.rating || '4.9' }}</span>
                  <span>月售{{ shop.monthlySales || '345' }}单</span>
                </div>
              
                <!-- 配送信息 -->
                <div class="flex text-xs text-gray-500">
                  <span class="mr-2">¥{{ shop.minOrderPrice || '15' }}起送</span>
                  <span class="mr-2">|</span>
                  <span class="mr-2">¥{{ shop.deliveryFee || '3' }}配送</span>
                </div>

                <!-- 店铺分类 -->
                <p class="text-xs text-gray-500 mt-1">{{ shop.category || '各种饺子' }}</p>
              </div>
              
              <!-- 促销和配送信息 -->
              <div>
                <!-- 促销信息 -->
                <div class="flex flex-col gap-1 mb-2" v-if="shop.promotions && shop.promotions.length">
                  <span 
                    v-for="(promo, i) in shop.promotions" 
                    :key="i"
                    class="inline-flex items-center text-xs px-1.5 py-0.5 rounded border"
                    :class="{
                      'text-gray-500 border-orange-200': promo.type === 'new_user',
                      'text-gray-500 border-blue-200': promo.type === 'special'
                    }"
                  >
                    <span class="bg-#70BC46 font-normal text-white mr-1">{{ promo.type === 'new_user' ? '新' : '特' }}</span>
                    {{ promo.text }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    <Footer class="fixed bottom-0 w-full"/>
  </div>
</template>

<script setup>
  import 'swiper/css/autoplay';
  import 'swiper/css';
  import 'swiper/css/pagination';
  import 'swiper/css/navigation';
  import Footer from '@/components/Footer.vue'
  import usecategories from '@/hooks/usecategories'
  import usebusinessinfoes from '@/hooks/usebusinessinfoes'
  import { useRouter } from 'vue-router'; 

  const router = useRouter();
  const {categories} = usecategories()
  const {businessinfoes} = usebusinessinfoes()

  // 跳转实现
  const goToBusinessInfo = (id) => {
    router.push({ path: '/businessinfo', query: { id } });
  };
</script>

<style scoped>
.bg-primary {
  background-color: #0097FF;
}
/* 分割线 */
.d-border {
  border-bottom: 1px solid rgb(165, 163, 163);
}
</style>